from django.http import HttpResponse
from django.http import JsonResponse
from django.shortcuts import render

# Create your views here.

# 定义类视图
from django.utils.decorators import method_decorator
from django.views import View


class ClassView(View):
    def get(self, request):
        return HttpResponse('类视图get函数')

    def post(self, request):
        return HttpResponse('类视图post函数')


# 定义装饰器
def my_decorator(func):
    def wrapper(request):
        print('装饰器被执行了')
        return func(request)
    return wrapper


@method_decorator(my_decorator, name='get')
class TemplateView(View):

    def get(self, request):
        return HttpResponse('shuaiqi')

    def post(self, request):
        json_dict = {"name": "xy", "age": 12}
        return JsonResponse(json_dict)